package com.atXiao.滑动窗口;

//209
public class 长度最小的子数组 {

    public static void main(String[] args) {
        int target=7;
        int nums[]={2,3,1,2,4,3};
        int res = minSubArrayLen(target, nums);
        System.out.println(res);
    }
    public static int minSubArrayLen(int target, int[] nums) {
        int left = 0;
        int right = 0;
        int currentSum = 0;
        int minLength = 0;
        //双指针进行探测，左右指针全部从最左边出发，边界为数组的长度
        while (right < nums.length) {
            //求和
            currentSum += nums[right];
            //跳出条件
            while (currentSum >= target) {
                //判断是否要去更新值
                if (right - left + 1  <minLength || minLength == 0) {
                    minLength = right - left+1;
                        //记性缩小窗口
                        //更新的条件？？？？？？
                }
                currentSum=currentSum-nums[left];
                left++;
            }
            right++;
        }
        return minLength;
    }

}
